<?php

namespace app\model;

use Illuminate\Database\Eloquent\Model;

class User extends Model
{
    protected $table = 'users';
    
    protected $fillable = [
        'nickname',
        'avatar',
        'wechat_openid',
        'wechat_unionid',
        'total_score',
        'created_at',
        'updated_at'
    ];

    protected $casts = [
        'total_score' => 'integer',
        'created_at' => 'datetime',
        'updated_at' => 'datetime',
    ];

    /**
     * 更新用户总分
     */
    public function updateTotalScore($score)
    {
        $this->total_score += $score;
        $this->save();
    }
}
